﻿namespace JxcLite.Pages.Report;

/// <summary>
/// 业务单据明细表。
/// </summary>
public class BillDetail : BaseTablePage<BillDetailInfo>
{
    private IReportService Service;

    /// <summary>
    /// 取得业务单据类型（进货、进退货、销货、销退货）。
    /// </summary>
    protected virtual string Type { get; }

    protected override async Task OnInitPageAsync()
    {
        await base.OnInitPageAsync();
        Service = await CreateServiceAsync<IReportService>();
        Table.OnQuery = QueryBillDetailsAsync;
        Table.Column(c => c.Status).Template((b, r) => b.Tag(r.Status));
        Table.Column(c => c.SettleMode).Template((b, r) => b.Tag(r.SettleMode));
        Table.Column(c => c.BillDate).Type(FieldType.Date);
    }

    [Action] public Task Export() => Table.ExportDataAsync();

    private Task<PagingResult<BillDetailInfo>> QueryBillDetailsAsync(PagingCriteria criteria)
    {
        criteria.SetQuery(nameof(BillDetailInfo.Type), QueryType.Equal, Type);
        return Service.QueryBillDetailsAsync(criteria);
    }
}